import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { render } from '@/utils/common/renderUtils';
import { sjlyOptionsListApi } from '@/api/wyf/pms/select';
import { xzqhTreeSelectListApi } from '@/api/wyf/xzqh/select';
import { filterDictTextByCache } from '/@/utils/dict/JDictSelectUtil';
import { h } from 'vue';
import { gxqyOptionsListApi } from '@/api/wyf/user/gxqySelect';
//import { rules } from '/@/utils/helper/validator';
// import { render } from '/@/utils/common/renderUtils';
// import { getWeekMonthQuarterYear } from '/@/utils';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '房源编号',
    align: 'left',
    width: 200,
    dataIndex: 'wyfbh',
    //resizable: true,
  },
  {
    title: '房源名称',
    align: 'left',
    dataIndex: 'fh',
    width: 100,
  },
  {
    title: '管辖单位',
    align: 'left',
    dataIndex: 'gxdwmc',
    width: 100,
    // resizable: true,
  },
  {
    title: '所属区域',
    align: 'left',
    dataIndex: 'xzqh_dictText',
    width: 280,
    // resizable: true,
  },
  {
    title: '详细地址',
    align: 'left',
    dataIndex: 'fwdz',
    width: 200,
    // resizable: true,
  },
  {
    title: '住客信息',
    align: 'left',
    width: 200,
    //dataIndex: 'jyrxm',
    customRender: ({ text, record }) => {
      let xm = '-',
        zjhm = '',
        lxdh = '',
        rzbz = '';
      if (record.tenantsList && record.tenantsList.length > 0) {
        const detail = record.tenantsList[0];
        xm = detail?.xm || '-';
        zjhm = detail?.zjhm || '';
        lxdh = detail?.lxdh || '';
        rzbz = detail?.rzbz || '';
      }
      const rzbzText = rzbz ? filterDictTextByCache('rzbz', rzbz) : '';
      const color = rzbz == '1' ? 'text-green' : 'text-red';
      return h('div', { class: 'zkxx' }, [
        h('div', null, `${xm}`),
        h('div', null, `${zjhm}`),
        h('div', null, `${lxdh}`),
        h('div', { class: color }, `${rzbzText ? rzbzText : ''}`),
      ]);
    },
  },
  {
    title: '实际入住人数',
    align: 'left',
    dataIndex: 'sjrzrs',
    width: 120,
  },

  {
    title: '实际居住时间',
    align: 'center',
    width: 160,
    customRender: ({ record }) => {
      return (record['sjrzsj'] ?? '') + ' ~ ' + (record['sjldsj'] ?? '');
    },
  },

  {
    title: '入住状态',
    align: 'center',
    dataIndex: 'zkzt',
    width: 120,
    customRender: ({ text }) => {
      return render.renderDict(text, 'zkzt');
    },
  },
  {
    title: '数据来源',
    align: 'left',
    dataIndex: 'sjly_dictText',
    width: 170,
    // resizable: true,
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  // {
  //   field: 'xzqh',
  //   label: '所属区域',
  //   component: 'ApiTreeSelect',
  //   componentProps: {
  //     api: xzqhTreeSelectListApi,
  //     params: {},
  //     resultField: 'result',
  //     multiple: true,
  //   },
  // },
  {
    label: '房源名称',
    field: 'fh',
    component: 'Input', //渲染的组件
    componentProps: {
      //  dictCode: 'status',
    },
  },
  {
    field: 'gxqy',
    label: '管辖单位',
    //component: 'ApiTreeSelect',
    component: 'JCascader',
    componentProps: {
      api: gxqyOptionsListApi,
      params: {},
      //resultField: 'title',
      // fieldNames: {
      //   label: 'id_dictText',
      //   value: 'id',
      // },
      // multiple: true,
      changeOnSelect: true,
    },
  },
  {
    field: 'xzqh',
    label: '所属区域',
    //component: 'ApiTreeSelect',
    component: 'JCascader',
    componentProps: {
      api: xzqhTreeSelectListApi,
      params: {},
      //resultField: 'title',
      // fieldNames: {
      //   label: 'title',
      //   value: 'value',
      // },
      // multiple: true,
      changeOnSelect: true,
    },
  },
  {
    label: '房源编号',
    field: 'wyfbh',
    component: 'Input', //渲染的组件
    componentProps: {
      //  dictCode: 'status',
    },
  },
  {
    label: '详细地址',
    field: 'fwdz',
    component: 'Input', //渲染的组件
  },
  {
    label: '数据来源',
    field: 'sjly',
    component: 'ApiSelect', //渲染的组件
    //defaultValue: '', //设置默认值
    componentProps: {
      api: sjlyOptionsListApi,
      resultField: 'result',
      labelField: 'mc',
      valueField: 'id',
    },
  },
  {
    label: '管辖单位',
    field: 'gxdwmc',
    component: 'Input', //渲染的组件
  },
  {
    label: '认证状态',
    field: 'rzbz',
    component: 'JDictSelectTag', //渲染的组件
    //defaultValue: '', //设置默认值
    componentProps: {
      dictCode: 'rzbz',
    },
  },
  {
    label: '入住状态',
    field: 'zkzt',
    component: 'JDictSelectTag', //渲染的组件
    componentProps: {
      dictCode: 'zkzt',
    },
  },
  {
    label: '住客姓名',
    field: 'xm',
    component: 'Input', //渲染的组件
  },
  {
    label: '住客身份证号',
    field: 'zjhm',
    component: 'Input', //渲染的组件
  },
  // {
  //   label: '实际入住时间',
  //   field: 'sjrzsj_begin',
  //   component: 'RangeDate',
  //   componentProps: {
  //     //日期格式化
  //     format: 'YYYY/MM/DD',
  //     //范围文本描述用集合
  //   },
  // },
  // {
  //   label: '实际离店时间',
  //   field: 'sjldsj_end',
  //   component: 'RangeDate',
  //   componentProps: {
  //     //日期格式化
  //     format: 'YYYY/MM/DD',
  //     //范围文本描述用集合
  //   },
  // },
];

export const detailSchema = [
  {
    field: '房源信息',
    component: 'Input',
    label: '',
    slot: 'title1',
  },
  {
    label: '房源编号',
    field: 'wyfbh',
    component: 'Input',
  },
  {
    label: '管辖单位',
    field: 'gxdwmc',
    component: 'Input',
  },
  {
    label: '详细地址',
    field: 'fwdz',
    component: 'Input',
  },
  {
    label: '营业信息',
    field: 'fwjyzt',
    component: 'Input',
    render: (text) => {
      console.log(text, '字典');
      return filterDictTextByCache('fwjyzt', text);
    },
    color: (text) => {
      return text == 0 ? 'text-green' : text == 2 ? 'text-red' : 'text-waring';
    },
  },

  {
    field: '入住信息',
    component: 'Input',
    label: '',
    slot: 'title2',
  },
  {
    label: '订单来源',
    field: 'sjly_dictText',
    component: 'Input',
  },
  {
    label: '预定入住时间',
    field: 'ddkssj',
    component: 'Input',
  },
  {
    label: '预定离店时间',
    field: 'ddjssj',
    component: 'Input',
  },
  {
    label: '实际入住时间',
    field: 'sjrzsj',
    component: 'Input',
  },
  {
    label: '实际离店时间',
    field: 'sjldsj',
    component: 'JDictSelectTag',
    // required: true,
  },
  {
    field: 'sjrzrs',
    component: 'Input',
    label: '实际入住人数',
  },
];
